package org.dromara.oce.service;

import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import lombok.RequiredArgsConstructor;
import org.dromara.common.sse.dto.SseMessageDto;
import org.dromara.common.sse.utils.SseMessageUtils;
import org.dromara.system.mapper.SysUserRoleMapper;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author Pippin
 * @version 1.0
 * @date 2025/3/26 15:44
 */
@RequiredArgsConstructor
@Service
public class AuditorService {

    private final SysUserRoleMapper userRoleMapper;

    public void sendMessage(Long roleId,String msg){
        List<Long> userIds = userRoleMapper.selectUserIdsByRoleId(roleId);
        if(CollectionUtils.isNotEmpty(userIds)){
            SseMessageDto dto = new SseMessageDto();
            dto.setMessage(msg);
            dto.setUserIds(userIds);
            SseMessageUtils.publishMessage(dto);
        }
    }

}
